/***********************************
 * storage 本地存储工具
 **********************************/
const TOKEN = "TOKEN"
const LOGIN_INFO = "LOGIN_INFO"
export default {
    /**
     * 存储localStorage
     * @param table
     * @param settings
     */
    setLocal(table, settings) {
        var _set = JSON.stringify(settings)
        return localStorage.setItem(table, _set);
    },
    /**
     * 获取localStorage
     * @param table
     * @returns {null|any}
     */
    getLocal(table) {
        var data = localStorage.getItem(table);
        try {
            data = JSON.parse(data)
        } catch (err) {
            return null
        }
        return data;
    },


    /**
     * 移除localStorage
     * @param table
     */
    removeLocal(table) {
        return localStorage.removeItem(table);
    },
    /**
     * 清除localStorage
     */
    clearLocal() {
        return localStorage.clear();
    },
    /**
     * 清除sessionStorage
     */
    clearSession:function (){sessionStorage.clear()},
    /**
     * 存储sessionStorage
     * @param key
     * @param data
     */
    setSession(key, data) {
        var _set = JSON.stringify(data)
        return sessionStorage.setItem(key, _set);
    },
    /**
     * 获取sessionStorage
     * @param key
     * @returns {null|any}
     */
    getSession(key) {
        var data = sessionStorage.getItem(key);
        try {
            data = JSON.parse(data)
        } catch (err) {
            return null
        }
        return data;
    },
    /**
     * 移除sessionStorage
     * @param key
     */
    removeSession(key) {
        return sessionStorage.removeItem(key);
    },



    /**
     * 存储Token
     * @param data
     */
    setToken:function (data){ sessionStorage.setItem(TOKEN,data) },
    /**
     * 获取Token
     * @returns {string}
     */
    getToken:function () { return sessionStorage.getItem(TOKEN) },
    /**
     * 存储登录信息
     * @param data
     */
    setLoginInfo:function (data){sessionStorage.setItem(LOGIN_INFO,JSON.stringify(data)) },
    /**
     * 获取登录信息
     * @returns {null|any}
     */
    getLoginInfo:function (){
        var data = sessionStorage.getItem(LOGIN_INFO);
        if(undefined!=data && null!=data){
            return JSON.parse(sessionStorage.getItem(LOGIN_INFO))
        }
        return null
    }
}